package com.xbongbong.pro.statistic.service.impl;

import com.xbongbong.paas.domain.entity.PaasMenuEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.elasticsearch.util.XbbElasticsearchRestTemplate;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.enums.PlatFormEnum;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.model.PaasMenuModel;
import com.xbongbong.paas.pojo.dto.UserInfoDTO;
import com.xbongbong.paas.pojo.vo.UserInfoVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.constant.ElasticConstant;
import com.xbongbong.pro.domain.entity.ChartEntity;
import com.xbongbong.pro.enums.TimeTypeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.service.toolbox.statistic.help.ChartDtoHelp;
import com.xbongbong.pro.statistic.enums.ReturnTypeEnum;
import com.xbongbong.pro.statistic.enums.SystemCodeEnum;
import com.xbongbong.pro.statistic.manager.feign.User4StatisticsFeignClient;
import com.xbongbong.pro.statistic.model.ChartModel;
import com.xbongbong.pro.statistic.pojo.FiscalYearTimePojo;
import com.xbongbong.pro.statistic.result.pojo.ChartIdPojo;
import com.xbongbong.pro.statistic.result.pojo.ChartResultPojo;
import com.xbongbong.pro.statistic.result.pojo.TitleRightPojo;
import com.xbongbong.pro.statistic.result.pojo.dto.ChartResultDTO;
import com.xbongbong.pro.statistic.result.pojo.vo.ChartResultDetailVO;
import com.xbongbong.pro.statistic.result.pojo.vo.ChartResultVO;
import com.xbongbong.pro.statistic.result.pojo.vo.ResultChartVO;
import com.xbongbong.pro.statistic.result.pojo.vo.ResultDataTableVO;
import com.xbongbong.pro.statistic.result.pojo.vo.ResultTableVO;
import com.xbongbong.pro.statistic.service.ChartResultService;
import com.xbongbong.pro.statistic.service.WorkbenchService;
import com.xbongbong.pro.statistic.service.result.ChartResult;
import com.xbongbong.pro.statistic.workbench.CockpitParamPojo;
import com.xbongbong.pro.statistic.workbench.ListParamPojo;
import com.xbongbong.pro.statistic.workbench.PointPojo;
import com.xbongbong.pro.statistic.workbench.pojo.dto.CommunicatePlanCountDTO;
import com.xbongbong.pro.statistic.workbench.pojo.dto.DataCockpitDTO;
import com.xbongbong.pro.statistic.workbench.vo.CommunicatePlanCountVO;
import com.xbongbong.pro.statistic.workbench.vo.DataCockpitVO;
import com.xbongbong.saas.constant.ParameterConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.CompanyConfigEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.CommunicatePlanEnum;
import com.xbongbong.saas.enums.subform.CommunicatePlanTeamEnum;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.enums.DataPermissionEnum;
import com.xbongbong.sys.model.CompanyConfigModel;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.join.query.HasChildQueryBuilder;
import org.elasticsearch.join.query.JoinQueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;

/**
 * 工作台
 * 创建时间 2021/2/4 4:15 PM
 * 修改时间 2021/2/4 4:15 PM
 * @author chy
 */
@Service("workbenchService")
public class WorkbenchServiceImpl implements WorkbenchService {
    private static final Logger LOG = LoggerFactory.getLogger(WorkbenchServiceImpl.class);
    @Resource
    private ChartModel chartModel;
    @Resource
    private ChartDtoHelp chartDtoHelp;
    @Resource
    private ChartResult chartResult;
    @Resource
    private User4StatisticsFeignClient user4StatisticsFeignClient;
    @Resource
    private ChartResultService chartResultService;
    @Resource
    private CompanyConfigModel companyConfigModel;
    @Resource
    private XbbElasticsearchRestTemplate xbbElasticsearchRestTemplate;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private PaasMenuModel paasMenuModel;

    @Override
    public DataCockpitVO dataCockpit(DataCockpitDTO dataCockpitDto) throws XbbException {

        String corpid = dataCockpitDto.getCorpid();
        String userId = dataCockpitDto.getUserId();

        UserVO userVo = getUserVo(corpid, userId);
        DataCockpitVO dataCockpitVO = new DataCockpitVO();
        setCustomerCount(userVo, dataCockpitVO);
        setFollowCustomerCount(userVo, dataCockpitVO);
        setContractCount(userVo, dataCockpitVO);
        setContractAmount(userVo, dataCockpitVO);
        setChartInfo(userVo, dataCockpitVO);
        dataCockpitVO.setUserId(userId);
        return dataCockpitVO;
    }

    private CockpitParamPojo getCockpitParamPojo(ChartEntity chartEntity, UserVO userVo) {
        CockpitParamPojo cockpitParamPojo = new CockpitParamPojo();
        //有全公司数据时，设置部门为根部门
        if (Objects.equals(userVo.getDataPermission(), DataPermissionEnum.ALL.getCode())) {
            cockpitParamPojo.setCheckedDepId(1L);
        }
        cockpitParamPojo.setCheckedUserId(userVo.getUserId());
        cockpitParamPojo.setSystemCode(chartEntity.getSystemCode());
        cockpitParamPojo.setTimeType(TimeTypeEnum.DAY.getCode());
        Long startTime = DateTimeUtil.getTodayInt();
        Long endTime = startTime + 86400;
        cockpitParamPojo.setStartTime(startTime);
        cockpitParamPojo.setEndTime(endTime);
        cockpitParamPojo.setId(chartEntity.getId());
        cockpitParamPojo.setCategoryId(chartEntity.getCategoryId());
        return cockpitParamPojo;
    }

    /**
     * 设置折线图信息
     * @param user
     * @param dataCockpitVO
     * @throws XbbException
     * 创建时间 2021/2/20 8:08 PM
     * 修改时间 2021/2/20 8:08 PM
     * @author chy
     */
    private void setChartInfo(UserVO user, DataCockpitVO dataCockpitVO) throws XbbException {

        String corpid = user.getCorpid();
        ChartResultDTO chartResultDTO = new ChartResultDTO();
        chartResultDTO.setCorpid(corpid);
        chartResultDTO.setReadCache(false);
        //数据权限
        Integer dataPermission = user.getDataPermission();
        if (Objects.equals(DataPermissionEnum.ALL.getCode(), dataPermission)) {
            chartResultDTO.setCompanyStructType(2);
            chartResultDTO.setCheckedDepId(1L);
        } else {
            chartResultDTO.setCompanyStructType(1);
            chartResultDTO.setCheckedUserId(user.getUserId());
        }

        //本周
        FiscalYearTimePojo timeFilter = new FiscalYearTimePojo();
        timeFilter.setTimeType(TimeTypeEnum.WEEK.getCode());
        chartResultDTO.setTimeFilter(timeFilter);
        //系统
        chartResultDTO.setStatisticsType(1);
        //对应的chart
        //新增客户数
        ChartEntity customerAddChart = chartModel.getSystemChartByCode(corpid, SystemCodeEnum.CUSTOMER_ADD_HOME);
        //跟进客户数
        ChartEntity customerFollowChart = chartModel.getSystemChartByCode(corpid, SystemCodeEnum.CUSTOMER_FOLLOW_HOME);
        //成交客户
        ChartEntity customerOkChart = chartModel.getSystemChartByCode(corpid, SystemCodeEnum.CUSTOMER_OK_HOME_COUNT);

        List<ChartIdPojo> idIn = new ArrayList<>();
        if (Objects.nonNull(customerAddChart)) {
            idIn.add(new ChartIdPojo(customerAddChart.getId(), customerAddChart.getStatisticsType()));
        }
        if (Objects.nonNull(customerFollowChart)) {
            idIn.add(new ChartIdPojo(customerFollowChart.getId(), customerAddChart.getStatisticsType()));
        }
        if (Objects.nonNull(customerOkChart)) {
            idIn.add(new ChartIdPojo(customerOkChart.getId(), customerAddChart.getStatisticsType()));
        }
        chartResultDTO.setChartIdIn(idIn);
        chartResultDTO.setLoginUser(user);


        ChartResultVO chartResultVO = chartResultService.chartResult(chartResultDTO);
        List<ChartResultDetailVO> chartList = chartResultVO.getChartList();
        for (ChartResultDetailVO chartResultDetailVO : chartList) {
            List<PointPojo> pointList = getPointList(chartResultDetailVO);
            Long chartId = chartResultDetailVO.getChartId();
            if (Objects.equals(customerAddChart.getId(), chartId)) {
                dataCockpitVO.setAddCustomerList(pointList);
            }
            if (Objects.equals(customerFollowChart.getId(), chartId)) {
                dataCockpitVO.setFollowCustomerList(pointList);
            }
            if (Objects.equals(customerOkChart.getId(), chartId)) {
                dataCockpitVO.setDealCustomerList(pointList);
            }
        }
    }

    /**
     * 获取客户数并放入返回数据中,设置列表返回参数
     * @param userVO
     * @param dataCockpitVO
     * @throws XbbException
     */
    private void setCustomerCount(UserVO userVO, DataCockpitVO dataCockpitVO) throws XbbException {
        UserEntity userEntity = BeanUtil.copyProperties(userVO, UserEntity.class, false);
        SystemCodeEnum systemCodeEnum = SystemCodeEnum.CUSTOMER_ADD_HOME_BOARD;

        //模拟前端请求，初始化chartResultDTO
        ChartResultDTO chartResultDTO = new ChartResultDTO();
        FiscalYearTimePojo timeFilter = new FiscalYearTimePojo();
        timeFilter.setTimeType(TimeTypeEnum.DAY.getCode());
        chartResultDTO.setTimeFilter(timeFilter);
        chartResultDTO.setCorpid(userVO.getCorpid());
        chartResultDTO.setReadCache(false);
        //数据权限
        Integer dataPermission = userVO.getDataPermission();
        if (Objects.equals(DataPermissionEnum.ALL.getCode(), dataPermission)) {
            chartResultDTO.setCompanyStructType(2);
            chartResultDTO.setCheckedDepId(1L);
        } else {
            chartResultDTO.setCompanyStructType(1);
            chartResultDTO.setCheckedUserId(userVO.getUserId());
        }
        ChartEntity chartEntity = chartModel.getSystemChartByCode(userVO.getCorpid(), systemCodeEnum);
        if (Objects.isNull(chartEntity)) {
            return ;
        }
        chartResultDTO.setUserId(userVO.getUserId());
        ChartResultPojo chartResultPojo = chartDtoHelp.getChartResultPojo4Base(userEntity, chartResultDTO);
        chartEntity.setSystemCode(systemCodeEnum.getSystemCode());
        chartResultPojo.setChartEntity(chartEntity);
        chartResultPojo.setSystemCodeEnum(systemCodeEnum);
        String total = (String) chartResult.getResult4System(ReturnTypeEnum.VALUE_RETURN, systemCodeEnum.getXbbRefTypeEnum(), chartResultPojo, null);
        dataCockpitVO.setCustomerCount(total);
        dataCockpitVO.setCustomerCockpitParamPojo(getCockpitParamPojo(chartEntity, userVO));
    }

    /**
     * 获取跟进客户数并放入返回数据中,设置列表返回参数
     * @param userVO
     * @param dataCockpitVO
     * @throws XbbException
     * 创建时间 2021/2/20 8:01 PM
     * 修改时间 2021/2/20 8:01 PM
     * @author chy
     */
    private void setFollowCustomerCount(UserVO userVO, DataCockpitVO dataCockpitVO) throws XbbException {

        UserEntity userEntity = BeanUtil.copyProperties(userVO, UserEntity.class, false);
        SystemCodeEnum systemCodeEnum = SystemCodeEnum.CUSTOMER_FOLLOW_BOARD;

        //模拟前端请求，初始化chartResultDTO
        ChartResultDTO chartResultDTO = new ChartResultDTO();
        FiscalYearTimePojo timeFilter = new FiscalYearTimePojo();
        timeFilter.setTimeType(TimeTypeEnum.DAY.getCode());
        chartResultDTO.setTimeFilter(timeFilter);
        chartResultDTO.setCorpid(userVO.getCorpid());
        chartResultDTO.setReadCache(false);
        //数据权限
        Integer dataPermission = userVO.getDataPermission();
        if (Objects.equals(DataPermissionEnum.ALL.getCode(), dataPermission)) {
            chartResultDTO.setCompanyStructType(2);
            chartResultDTO.setCheckedDepId(1L);
        } else {
            chartResultDTO.setCompanyStructType(1);
            chartResultDTO.setCheckedUserId(userVO.getUserId());
        }
        ChartEntity chartEntity = chartModel.getSystemChartByCode(userVO.getCorpid(), systemCodeEnum);
        if (Objects.isNull(chartEntity)) {
            return;
        }
        chartResultDTO.setUserId(userVO.getUserId());
        ChartResultPojo chartResultPojo = chartDtoHelp.getChartResultPojo4Base(userEntity, chartResultDTO);
        chartEntity.setSystemCode(systemCodeEnum.getSystemCode());
        chartResultPojo.setChartEntity(chartEntity);
        chartResultPojo.setSystemCodeEnum(systemCodeEnum);
        String total = (String) chartResult.getResult4System(ReturnTypeEnum.VALUE_RETURN, systemCodeEnum.getXbbRefTypeEnum(), chartResultPojo, null);
        dataCockpitVO.setFollowCustomerCount(total);
        dataCockpitVO.setFollowCustomerCockpitParamPojo(getCockpitParamPojo(chartEntity, userVO));
    }

    /**
     * 获取合同数并放入返回数据中,设置列表返回参数
     * @param userVO
     * @param dataCockpitVO
     * @throws XbbException
     * 创建时间 2021/2/20 8:02 PM
     * 修改时间 2021/2/20 8:02 PM
     * @author chy
     */
    private void setContractCount(UserVO userVO, DataCockpitVO dataCockpitVO) throws XbbException {
        UserEntity userEntity = BeanUtil.copyProperties(userVO, UserEntity.class, false);
        SystemCodeEnum systemCodeEnum = SystemCodeEnum.CONTRACT_COUNT_BOARD;

        //模拟前端请求，初始化chartResultDTO
        ChartResultDTO chartResultDTO = new ChartResultDTO();
        FiscalYearTimePojo timeFilter = new FiscalYearTimePojo();
        timeFilter.setTimeType(TimeTypeEnum.DAY.getCode());
        chartResultDTO.setTimeFilter(timeFilter);
        chartResultDTO.setCorpid(userVO.getCorpid());
        chartResultDTO.setReadCache(false);
        //数据权限
        Integer dataPermission = userVO.getDataPermission();
        if (Objects.equals(DataPermissionEnum.ALL.getCode(), dataPermission)) {
            chartResultDTO.setCompanyStructType(2);
            chartResultDTO.setCheckedDepId(1L);
        } else {
            chartResultDTO.setCompanyStructType(1);
            chartResultDTO.setCheckedUserId(userVO.getUserId());
        }
        ChartEntity chartEntity = chartModel.getSystemChartByCode(userVO.getCorpid(), systemCodeEnum);
        if (Objects.isNull(chartEntity)) {
            return;
        }
        chartResultDTO.setUserId(userVO.getUserId());
        ChartResultPojo chartResultPojo = chartDtoHelp.getChartResultPojo4Base(userEntity, chartResultDTO);
        chartEntity.setSystemCode(systemCodeEnum.getSystemCode());
        chartResultPojo.setChartEntity(chartEntity);
        chartResultPojo.setSystemCodeEnum(systemCodeEnum);
        String total = (String) chartResult.getResult4System(ReturnTypeEnum.VALUE_RETURN, systemCodeEnum.getXbbRefTypeEnum(), chartResultPojo, null);
        dataCockpitVO.setContractCount(total);
        dataCockpitVO.setContractCockpitParamPojo(getCockpitParamPojo(chartEntity, userVO));
    }

    /**
     * 获取合同金额数并放入返回数据中,设置列表返回参数
     * @param userVO
     * @param dataCockpitVO
     * @throws XbbException
     * 创建时间 2021/2/20 8:03 PM
     * 修改时间 2021/2/20 8:03 PM
     * @author chy
     */
    private void setContractAmount(UserVO userVO, DataCockpitVO dataCockpitVO) throws XbbException {
        UserEntity userEntity = BeanUtil.copyProperties(userVO, UserEntity.class, false);
        SystemCodeEnum systemCodeEnum = SystemCodeEnum.CONTRACT_AMOUNT_BOARD;

        //模拟前端请求，初始化chartResultDTO
        ChartResultDTO chartResultDTO = new ChartResultDTO();
        FiscalYearTimePojo timeFilter = new FiscalYearTimePojo();
        timeFilter.setTimeType(TimeTypeEnum.DAY.getCode());
        chartResultDTO.setTimeFilter(timeFilter);
        chartResultDTO.setCorpid(userVO.getCorpid());
        chartResultDTO.setReadCache(false);
        //数据权限
        Integer dataPermission = userVO.getDataPermission();
        if (Objects.equals(DataPermissionEnum.ALL.getCode(), dataPermission)) {
            chartResultDTO.setCompanyStructType(2);
            chartResultDTO.setCheckedDepId(1L);
        } else {
            chartResultDTO.setCompanyStructType(1);
            chartResultDTO.setCheckedUserId(userVO.getUserId());
        }
        ChartEntity chartEntity = chartModel.getSystemChartByCode(userVO.getCorpid(), systemCodeEnum);
        if (Objects.isNull(chartEntity)) {
            return;
        }
        chartResultDTO.setUserId(userVO.getUserId());
        ChartResultPojo chartResultPojo = chartDtoHelp.getChartResultPojo4Base(userEntity, chartResultDTO);
        chartEntity.setSystemCode(systemCodeEnum.getSystemCode());
        chartResultPojo.setChartEntity(chartEntity);
        chartResultPojo.setSystemCodeEnum(systemCodeEnum);
        //万元开关是否开启
        boolean thousandSwitch = companyConfigModel.hasBeenEnable(userVO.getCorpid(), CompanyConfigEnum.THOUSAND_SWITCH.getAlias(), "1");
        chartResultPojo.setThousandSwitch(thousandSwitch);
        String total = (String) chartResult.getResult4System(ReturnTypeEnum.VALUE_RETURN, systemCodeEnum.getXbbRefTypeEnum(), chartResultPojo, null);
        dataCockpitVO.setContractAmount(total);
        dataCockpitVO.setThousandSwitch(thousandSwitch);
        dataCockpitVO.setContractAmountCockpitParamPojo(getCockpitParamPojo(chartEntity, userVO));
    }

    /**
     * 获取用户和权限信息
     * @param corpid
     * @param userId
     * @return
     * @throws XbbException
     * 创建时间 2021/2/20 7:54 PM
     * 修改时间 2021/2/20 7:54 PM
     * @author chy
     */
    private UserVO getUserVo(String corpid, String userId) throws XbbException {
        UserInfoDTO userInfoDTO = new UserInfoDTO();
        userInfoDTO.setCorpid(corpid);
        userInfoDTO.setUserId(userId);
        userInfoDTO.setPlatform(PlatFormEnum.INTERNAL.getValue());
        userInfoDTO.setPaasPermissionsFlag(true);
        userInfoDTO.setUserDetailFlag(true);
        userInfoDTO.setCompanyInfoFlag(false);
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<UserInfoVO> userInfoResp = user4StatisticsFeignClient.getUserInfo(userInfoDTO, lang);
        UserInfoVO userInfo;
        if (userInfoResp.isSuccess()) {
            userInfo = userInfoResp.getResult();
        } else {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100004);
        }
        return userInfo.getUser();
    }

    @Override
    public CommunicatePlanCountVO communicatePlanCount(CommunicatePlanCountDTO communicatePlanCountDTO) throws XbbException {
        Long startAddTime = DateTimeUtil.getTodayInt();
        Long endAddTime = startAddTime + 86400L;
        String corpid = communicatePlanCountDTO.getCorpid();
        String userId = communicatePlanCountDTO.getUserId();
        BoolQueryBuilder boolQueryBuilder = boolQuery();
        boolQueryBuilder.filter(termQuery("corpid.keyword", corpid));
        boolQueryBuilder.filter(termQuery(ParameterConstant.DEL, DelEnum.NORMAL.getDel()));
        boolQueryBuilder.filter(rangeQuery(CommunicatePlanEnum.getEsAttr4Keyword(CommunicatePlanEnum.COMMUNICATE_TIME)).
                gte(startAddTime).lt(endAddTime));
        boolQueryBuilder.filter(termQuery(ElasticConstant.MY_JOIN_FIELD, IndexTypeEnum.IDX_SAAS_COMMUNICATE_PLAN.getType()));
        BoolQueryBuilder teamQueryBuilder = boolQuery();
        teamQueryBuilder.filter(termQuery("corpid.keyword", corpid));
        teamQueryBuilder.filter(termQuery(CommunicatePlanTeamEnum.getEsAttr(CommunicatePlanTeamEnum.USER_ID), userId));
        teamQueryBuilder.filter(termQuery(StringConstant.DEL, DelEnum.NORMAL.getDel()));
        HasChildQueryBuilder hasChildQueryBuilder = JoinQueryBuilders.hasChildQuery(IndexTypeEnum.IDX_SAAS_COMMUNICATE_PLAN_TEAM.getType(), teamQueryBuilder, ScoreMode.Max);
        boolQueryBuilder.filter(hasChildQueryBuilder);
        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
        sourceBuilder.query(boolQueryBuilder);
        SearchRequest searchRequest = new SearchRequest(IndexTypeEnum.IDX_SAAS_COMMUNICATE_PLAN.getIndex());
        searchRequest.source(sourceBuilder);
        CountRequest countRequest = new CountRequest(searchRequest.indices()[0]);
        countRequest.query(searchRequest.source().query());
        Long countLong = xbbElasticsearchRestTemplate.count(countRequest);
        CommunicatePlanCountVO communicatePlanCountVO = new CommunicatePlanCountVO();
        communicatePlanCountVO.setCommunicatePlanCount(countLong.toString());
        communicatePlanCountVO.setUserId(userId);
        ListParamPojo customerListParamPojo = getListParamPojo(XbbRefTypeEnum.CUSTOMER, corpid);
        ListParamPojo contactListParamPojo = getListParamPojo(XbbRefTypeEnum.CONTACT, corpid);
        ListParamPojo communicateListParamPojo = getListParamPojo(XbbRefTypeEnum.CUSTOMER_COMMUNICATE, corpid);
        UserVO userVo = getUserVo(corpid, userId);
        ListParamPojo communicatePlanListParamPojo = getListParamPojo(XbbRefTypeEnum.COMMUNICATE_PLAN, corpid);
        communicatePlanListParamPojo.setIsAdminOrBoss(userVo.isAdminOrBoss());
        communicatePlanCountVO.setCustomerListParamPojo(customerListParamPojo);
        communicatePlanCountVO.setContactListParamPojo(contactListParamPojo);
        communicatePlanCountVO.setCommunicateListParamPojo(communicateListParamPojo);
        communicatePlanCountVO.setCommunicatePlanListParamPojo(communicatePlanListParamPojo);
        return communicatePlanCountVO;
    }

    private ListParamPojo getListParamPojo(XbbRefTypeEnum xbbRefTypeEnum, String corpid) {
        PaasMenuEntity paasMenu = paasMenuModel.getByAlias(xbbRefTypeEnum.getAlias(), corpid);
        Integer subBusinessType = xbbRefTypeEnum.getCode();
        Integer saasMark =  paasMenu.getSaasMark();
        Long menuId = paasMenu.getId();
        Long appId = paasMenu.getAppId();
        ListParamPojo listParamPojo = new ListParamPojo();
        listParamPojo.setSubBusinessType(subBusinessType);
        listParamPojo.setSaasMark(saasMark);
        listParamPojo.setMenuId(menuId);
        listParamPojo.setAppId(appId);
        if (Objects.equals(xbbRefTypeEnum, XbbRefTypeEnum.COMMUNICATE_PLAN)) {
            listParamPojo.setBusinessType(subBusinessType);
            PaasFormEntityExt paasForm = paasFormModel.getByBusinessType(xbbRefTypeEnum.getCode(), corpid);
            listParamPojo.setFormId(paasForm.getId());
        }
        return listParamPojo;
    }

    private List<PointPojo> getPointList(ChartResultDetailVO chartResultDetailVO) {
        ResultTableVO table = chartResultDetailVO.getTable();
        ResultChartVO chart = chartResultDetailVO.getChart().get(0);
        String name = chart.getLegend().get(0);
        List<TitleRightPojo> titles = table.getTitle();
        List<ResultDataTableVO> datas = table.getData().get(0);
        List<PointPojo> pointList = new ArrayList<>();
        for (int i = 1; i < titles.size(); i++) {
            TitleRightPojo titleRightPojo = titles.get(i);
            String titleValue = titleRightPojo.getTitleValue();
            ResultDataTableVO resultDataTableVO = datas.get(i);
            String value = resultDataTableVO.getValue();
            PointPojo pointPojo = new PointPojo();
            pointPojo.setValue(value);
            pointPojo.setDate(titleValue);
            pointPojo.setType(name);
            pointList.add(pointPojo);
        }
        return pointList;
    }



}
